package demo1;

public class Test {
    public static void swap(int x, int y){
        int tmp = x;
        x = y;
        y = x;
    }

    public static void swap(MyVal val1, MyVal val2){
        int tmp = val1.val;
        val1.val = val2.val;;
        val2.val = tmp;
    }

    public static void main(String[] args) {
        Fruit apple = new Apple("苹果1", "红色", 20);

        Fruit banana = new Banana("香蕉", "黄色");

    }

    public static void main4(String[] args) {
        MyVal myVal1 = new MyVal();
        myVal1.val = 10;
        MyVal myVal2 = new MyVal();
        myVal2.val = 20;

        System.out.println("交换前: myVal1.val = " + myVal1.val + ", myVal2.val = " + myVal2.val);
        swap(myVal1, myVal2);
        System.out.println("交换后: myVal1.val = " + myVal1.val + ", myVal2.val = " + myVal2.val);
    }

    public static void main3(String[] args) {
        int a = 10;
        int b = 20;
        System.out.println("交换前: a = " + a + ", b = " + b);
        swap(a, b);
        System.out.println("交换后: a = " + a + ", b = " + b);
    }

    public static void main2(String[] args) {
        Apple apple1 = new Apple("苹果1", "红色", 1.3);
        System.out.println(apple1);
    }

    public static void main1(String[] args) {
        Fruit apple = new Fruit("苹果", "红色");
        Fruit banana = new Fruit("香蕉", "红色");
        System.out.println(apple);
        System.out.println(banana);
    }
}
